/******************************************************************************/
/*  Class AT25DFxxx                                                           */
/*  PO: S. Maslyakov, rusoil.9@gmail.com                                      */
/*                                                                            */
/*  Revision:     1.0                                                         */
/*  Date:         2010/12/21 18:46:33                                         */
/******************************************************************************/


#ifndef __AT25DF_H
#define __AT25DF_H


#include "data_types.h"
#include "At25df\at25df_def.h"


//==============================================================================
//  Class AT25DF
//==============================================================================
class AT25DF
{
public:
  static void Init_At25df();
  inline static bool_t GetFlashStatus() { return m_isFlashOk; }
  inline static uint8_t GetFamilyCode() { return m_familyCode; }
  inline static uint8_t GetDensityCode() { return m_densityCode; }
  static uint32_t ReadDataBytes(const __AT25DF_DATA * const _pData);
  static uint32_t ProgramPage(const __AT25DF_DATA * const _pData);
  static uint32_t ChipErase(const uint32_t _password);
  static uint32_t BlockErase(const __AT25DF_ADDRESS _addr,
                             const __eAt25DF_BLOCK _block);
    
private:
  inline static void SelectChip() { FIO0CLR_bit.P0_16 = 1; }
  inline static void LockChip() { FIO0SET_bit.P0_16 = 1; }
  static uint16_t ReadStatusReg();
  static void ReadId(uint8_t * const _pId);
  static void WriteEnable();
  static void WriteDisable();
  static bool_t IsBusy();
  static bool_t IsWriteEnable();
  static uint32_t ProtectSector(const __AT25DF_ADDRESS _addr);
  static uint32_t UnprotectSector(const __AT25DF_ADDRESS _addr);
  static bool_t IsSectorProtect(const __AT25DF_ADDRESS _addr);

  static bool_t m_isFlashOk;
  static uint8_t m_familyCode;
  static uint8_t m_densityCode;
};
//==============================================================================
//==============================================================================


#endif